package com.hmall.mq;


import com.hmall.constants.ItemMqConstants;
import com.hmall.service.ItemSearchService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author dml
 * Date on 2022/7/10 0010
 */

@Component
public class ItemListener {
     @Autowired
     private ItemSearchService itemSearchService;


//    @RabbitListener(queues= ItemMqConstants.INSERT_QUEUE_NAME)
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "up.queue"),
            exchange = @Exchange(name = "item.topic", type = ExchangeTypes.TOPIC),
            key = "item.up"
    ))

    public void listenHotelInsertOrUpdate(Long id){
        itemSearchService.updateById(id);
    }



//    @RabbitListener(queues= ItemMqConstants.DELETE_QUEUE_NAME)
    public void listenHotelDelete(Long id){
        itemSearchService.deleteById(id);
    }
}
